package com.czy.owner.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;

import java.util.List;


/**
 * Created by wangyang on 2016/12/9 0016.
 */
public class ProvinceCharAdapter extends BaseRecyclerAdapter<String, ProvinceCharAdapter.ProvinceCodeHolder> {
    private String selectedProvinceCode;
    public ProvinceCharAdapter(Context context, List<String> data, String provinceCode) {
        super(context, data);
        this.selectedProvinceCode = provinceCode;

    }

    @Override
    public void onBindViewHolder(ProvinceCodeHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    @Override
    public ProvinceCodeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ProvinceCodeHolder(layoutInflater.inflate(R.layout.item_province_code_recycler, parent, false));
    }

    public class ProvinceCodeHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tvProvinceCodeItem;

        public ProvinceCodeHolder(View itemView) {
            super(itemView);
            tvProvinceCodeItem = (TextView) itemView.findViewById(R.id.tv_province_code_item);
        }

        public void bindData(String mProvinceCode){
            if(selectedProvinceCode.equals(mProvinceCode)){
                tvProvinceCodeItem.setTextColor(ContextCompat.getColor(mContext, R.color.white));
                tvProvinceCodeItem.setBackground(ContextCompat.getDrawable(mContext, R.mipmap.icon_province_code_bg));
            }else {
                tvProvinceCodeItem.setTextColor(ContextCompat.getColor(mContext, R.color.black));
//                tvProvinceCodeItem.setBackground(ContextCompat.getDrawable(mContext, R.color.white));
            }
            tvProvinceCodeItem.setText(mProvinceCode);

        }
    }
}
